const {
  $util,
} = getApp();
Page({
  data: {
    list: [],
    page: 1,
    hasMore: true,
    typ: 0, // 奖惩类别 0-荣誉 1-惩处
    nav: [{
      id: 0,
      title: '荣誉',
    }, {
      id: 1,
      title: '惩处',
    }],
    isfalse: false,
  },
  onLoad(ops) {
    wx.setNavigationBarTitle({
      title: '奖罚公示',
    });
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadData();
    });
  },
  changeNav(e) {
    this.setData({
      page: 1,
      typ: e.detail.obj.id,
    }, () => {
      this.loadData();
    });
  },
  loadData() {
    const {
      page,
      typ,
    } = this.data;
    $util.request({
      url: 'entry/wxapp/partyman.repunish.getRepunishList',
      data: {
        type: typ,
        page,
      },
      success: (res) => {
        let list = res.data;
        if (page > 1) {
          list = [...this.data.list, ...list];
        }
        this.setData({
          hasMore: Number(res.total) > list.length,
          page: Number(res.total) > list.length ? page + 1 : page,
          list,
          isLoad: true,
        });
      },
    });
  },
  onReachBottom() {
    if (this.data.hasMore) {
      this.loadData();
    }
  },
});